package com.bookmarket.controller;

import com.bookmarket.entity.Order;
import com.bookmarket.service.CzgIOrderService;
import com.github.pagehelper.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Chen Zhaoguang
 * @date 2017/12/26 14:52
 */
@RestController
@RequestMapping("/czgOrder")
public class CzgOrderController {

    @Resource
    private CzgIOrderService czgIOrderService;

    //分页查询，模糊查询
    @RequestMapping("/queryByPage")
    public Map queryByPage(int pageNum, int pageSize, Order order){
        Map map = new HashMap();
        /*ModelAndView mv = new ModelAndView();*/
        map.put("pageSize", pageSize);
        map.put("pageNum", pageNum);
        map.put("order",order);
        Page page = czgIOrderService.queryLikeOrders(map);
        map.put("page",page);
        map.put("totalPage",page.getPages());
        /*mv.addObject("map",map);
        mv.setView(new MappingJackson2JsonView());*/
        return map;
    }


    //分页查询，模糊查询
    //申请退货
    @RequestMapping("/querySTByPage")
    public Map querySTByPage(int pageNum, int pageSize, Order order){
        Map map = new HashMap();
        /*ModelAndView mv = new ModelAndView();*/
        map.put("pageSize", pageSize);
        map.put("pageNum", pageNum);
        map.put("order",order);
        Page page = czgIOrderService.queryLikeSTOrders(map);
        map.put("page",page);
        map.put("totalPage",page.getPages());
        /*mv.addObject("map",map);
        mv.setView(new MappingJackson2JsonView());*/
        return map;
    }

    //分页查询，模糊查询
    //未发
    @RequestMapping("/queryWFByPage")
    public Map queryWFByPage(int pageNum, int pageSize, Order order){
        Map map = new HashMap();
        /*ModelAndView mv = new ModelAndView();*/
        map.put("pageSize", pageSize);
        map.put("pageNum", pageNum);
        map.put("order",order);
        Page page = czgIOrderService.queryLikeWFOrders(map);
        map.put("page",page);
        map.put("totalPage",page.getPages());
        /*mv.addObject("map",map);
        mv.setView(new MappingJackson2JsonView());*/
        return map;
    }

    //分页查询，模糊查询
    //已发
    @RequestMapping("/queryYFByPage")
    public Map queryYFByPage(int pageNum, int pageSize, Order order){
        Map map = new HashMap();
        /*ModelAndView mv = new ModelAndView();*/
        map.put("pageSize", pageSize);
        map.put("pageNum", pageNum);
        map.put("order",order);
        Page page = czgIOrderService.queryLikeYFOrders(map);
        map.put("page",page);
        map.put("totalPage",page.getPages());
        /*mv.addObject("map",map);
        mv.setView(new MappingJackson2JsonView());*/
        return map;
    }

    //分页查询，模糊查询
    //退货
    @RequestMapping("/queryTHByPage")
    public Map queryTHByPage(int pageNum, int pageSize, Order order){
        Map map = new HashMap();
        /*ModelAndView mv = new ModelAndView();*/
        map.put("pageSize", pageSize);
        map.put("pageNum", pageNum);
        map.put("order",order);
        Page page = czgIOrderService.queryLikeTHOrders(map);
        map.put("page",page);
        map.put("totalPage",page.getPages());
        /*mv.addObject("map",map);
        mv.setView(new MappingJackson2JsonView());*/
        return map;
    }

    @RequestMapping("/fahuo")
    public ModelAndView fahuo(Order order){
        ModelAndView mv = new ModelAndView();
        czgIOrderService.fahuoOrder(order);
        mv.setView(new MappingJackson2JsonView());
        return mv;
    }

    @RequestMapping("/tuihuo")
    public ModelAndView tuihuo(Order order){
        ModelAndView mv = new ModelAndView();
        czgIOrderService.tuihuoOrder(order);
        mv.setView(new MappingJackson2JsonView());
        return mv;
    }

    public void setCzgIOrderService(CzgIOrderService czgIOrderService) {
        this.czgIOrderService = czgIOrderService;
    }
}
